#include<bits/stdc++.h>
using namespace std;
const int N = 1001;
char a[N];
int sum[N];
int main()
{
	int ret = 0;
	cin>>a+1;
	int n = strlen(a+1);
	for(int i = 1;i<=n;i++)
	{
		sum[i] = sum[i-1] + a[i]=='L'?1:-1;
	}
	for(int i = 1;i<=n;i++)
	{
		for(int j = i+1;j<=n;j++)
		{
			if(sum[j] - sum[i-1]==0)
			ret = max(ret,j-i+1);
		}
	}
	cout<<ret;
	return 0;
}
